<%-- 
    Document   : userReport
    Created on : 01 Apr 12, 20:33:43
    Author     : DELL
--%>

<%@page import="bean.DataBaseConnection"%>
<%@page import="kontrol.customer"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<%
    bean.DataBaseConnection conn = new bean.DataBaseConnection();
%>

<html>
    <head>
        <link href='' rel='SHORTCUT ICON'/>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>CUSTOMER PAGE | ROUTER RENT CAR</title>
        <style>
            #main{
                font-weight: bold;
                padding-left:0px;
                padding-right:0px;
                margin-top: 30px;
                margin-left:150px;
                margin-right:75px;
                margin-bottom:0px;
            }

            #menuhor{
                list-style-type: disc;
                margin: 0;
                padding: 0;

                float: left;
            }
            #menuhor li {
                margin: 0;
                padding: 0 ;
                float: left;

            }
            #menuhor a {
                float: none;
                width: 150px;
                text-align: center;
                color: #FFF;
                text-decoration: none;
                padding: 2px;
                line-height: 2;
                margin-bottom: 3px;
            }
            #menuhor a:hover{
                background: brown;
            }

        </style>
    </head>
    <body background="images/space.jpg">

        <div id="main">
            <img alt="cover" src="images/cod.gif" width="1050" height="400">

            <br>
            </body>
            <div id="menuhor"style="position:absolute;right:7px;left:173px;top:370px;">
                <a href="home.html"><m style="color:whitesmoke;font-family:Tahoma;font-size:27px">  HOME </a></m>
                <a href="garasimobil.jsp"><m style="color:whitesmoke;font-family:Tahoma;font-size:27px">| GARASI MOBIL </a></m>
                <a href="form.jsp"><m style="color:whitesmoke;font-family:Tahoma;font-size:27px">| SEWA MOBIL</a></m> 
                <a href="kembali.jsp"><m style="color:whitesmoke;font-family:Tahoma;font-size:27px">|KEMBALI MOBIL</a></m>
                <a href="tentangkami.jsp"><m style="color:whitesmoke;font-family:Tahoma;font-size:27px">| KONTAK KAMI</a></m>
            </div><br> <br><br><br>

            <jsp:useBean id="kalk" scope="session" class="bean.DataBaseConnection"/>
            <jsp:setProperty name="kalk" property="nama" value="${param.nama}"/>
            <jsp:setProperty name="kalk" property="ttl" value="${param.ttl}"/>
            <jsp:setProperty name="kalk" property="alamat" value="${param.alamat}"/>
            <jsp:setProperty name="kalk" property="notlp" value="${param.notlp}"/>
            <jsp:setProperty name="kalk" property="noktp" value="${param.noktp}"/>
            <jsp:setProperty name="kalk" property="nosim" value="${param.nosim}"/>
            <jsp:setProperty name="kalk" property="tglsewa" value="${param.tglsewa}"/>
            <jsp:setProperty name="kalk" property="tglkembali" value="${param.tglkembali}"/> 
            <jsp:setProperty name="kalk" property="mobil" value="${param.mobil}"/>
            <center>
                <%
                    java.sql.Statement statement = conn.getConnection().createStatement();
                    java.sql.ResultSet result2 = null;

                    if (!kalk.getNama().isEmpty()) {
                        String querySisa = "select (status - tersewa) as sisa from statusmobil where mobil='" + kalk.getMobil() + "'";
                        java.sql.ResultSet result = statement.executeQuery(querySisa);
                        int sisa = 0;
                        if (result.next()) {
                            sisa = result.getInt(1);
                        }
                        if (sisa <= 0) {
                            out.print("error");
                        } else {
                            String query = "insert into customer values ('" + kalk.getNama() + "', '" + kalk.getTtl() + "' , '" + kalk.getAlamat() + "' , '" + kalk.getNotlp() + "' , '" + kalk.getNoktp() + "' , '" + kalk.getNosim() + "' , '" + kalk.getTglsewa() + "' , '" + kalk.getTglkembali() + "' , '" + kalk.getMobil() + "')";
                            statement.executeUpdate(query);
                            String queryjumlah = "select nvl(tersewa,0) from statusmobil where mobil='" + kalk.getMobil() + "'";
                            java.sql.ResultSet result1 = statement.executeQuery(queryjumlah);
                            int stat = 0;
                            if (result1.next()) {
                                stat = result1.getInt(1) + 1;
                            }

                            String querySewa = "UPDATE StatusMobil set tersewa = " + stat + " where mobil ='" + kalk.getMobil() + "'";
                            statement.executeUpdate(querySewa);
                            String query2 = "select nama, ttl, alamat, notlp, noktp, nosim, tglsewa, tglkembali, mobil from customer where nama = '" + kalk.getNama() + "' and ttl = '" + kalk.getTtl() + "' and alamat = '" + kalk.getAlamat() + "' and notlp = '" + kalk.getNotlp() + "' and noktp = '" + kalk.getNoktp() + "' and nosim = '" + kalk.getNosim() + "' and tglsewa = '" + kalk.getTglsewa() + "' and tglkembali = '" + kalk.getTglkembali() + "' and mobil = '" + kalk.getMobil() + "' ";
                            result2 = statement.executeQuery(query2);
                            kalk = new DataBaseConnection();
                        }
                    }

                    if(result2==null){
                        response.sendRedirect("form_error.jsp?error=Habis");
                    } else if (result2.next()) {

                %>

                <center><font color="black" size="5"><strong><p>Data Anda Sebagai Peminjam</p></strong></font></center>                      
                <table border="0" align="center">
                    <tr>
                        <td bgcolor="white"><font border="1"><b>Nama</b></font></td>
                        <td bgcolor="white"><font border="1">:&emsp;<% out.println(result2.getString("nama"));%></font></td></tr>
                    <tr>
                        <td bgcolor="white"><font border="1"><b>TTL</b></font></td>
                        <td bgcolor="white"><font border="1">:&emsp;<% out.println(result2.getString("ttl"));%></font></td></tr>
                    <tr>
                        <td bgcolor="white"><font border="1"><b>Alamat</b></font></td>
                        <td bgcolor="white"><font border="1">:&emsp;<% out.println(result2.getString("alamat"));%></font></td></tr>
                    <tr>
                        <td bgcolor="white"><font border="1"><b>No Tlp</b></font></td>
                        <td bgcolor="white"><font border="1">:&emsp;<% out.println(result2.getString("notlp"));%></font></td></tr>
                    <tr>
                        <td bgcolor="white"><font border="1"><b>No Ktp</b></font></td>
                        <td bgcolor="white"><font border="1">:&emsp;<% out.println(result2.getString("noktp"));%></font></td></tr>
                    <tr>
                        <td bgcolor="white"><font border="1"><b>No Sim</b></font></td>
                        <td bgcolor="white"><font border="1">:&emsp;<% out.println(result2.getString("nosim"));%></font></td></tr>
                    <tr>
                        <td bgcolor="white"><font border="1"><b>Tanggal Sewa</b></font></td>
                        <td bgcolor="white"><font border="1">:&emsp;<% out.println(result2.getString("tglsewa"));%></font></td></tr>
                    <tr>
                        <td bgcolor="white"><font border="1"><b>Tanggal Kembali</b></font></td>
                        <td bgcolor="white"><font border="1">:&emsp;<% out.println(result2.getString("tglkembali"));%></font></td></tr>
                    <tr>
                        <td bgcolor="white"><font border="1"><b>Nama Mobil</b></font></td>
                        <td bgcolor="white"><font border="1">:&emsp;<% out.println(result2.getString("mobil"));%></font></td></tr>

                </table>
                <%
                    } else
                        response.sendRedirect("form_error.jsp?error=yes");
                %>  
                <font face="Verdana" size="4" font color="white">
                    cetak Bukti penyewaan untuk mengambil mobil anda...</font>
                <font face="Verdana" size="6" color="#FF0000"></font><br>
                <font face="Verdana" size="2" font color="white">untuk mencetak bukti penyewaan</font>
                <a href="javascript:window.print()">Klik di sini </a>

            </center>
    </body>
</html>

